Radar Host Communication library  2020.08.13
commlib24_D2GL_basics.c
Go to the documentation of this file.
1 
14 /* ===========================================================================
15 ** Copyright (C) 2016-2021 Infineon Technologies AG
16 ** All rights reserved.
17 ** ===========================================================================
18 **
19 ** ===========================================================================
20 ** This document contains proprietary information of Infineon Technologies AG.
21 ** Passing on and copying of this document, and communication of its contents
22 ** is not permitted without Infineon's prior written authorisation.
23 ** ===========================================================================
24 */
25 
26 
27 /*
28 ==============================================================================
29  1. INCLUDE FILES
30 ==============================================================================
31 */
32 
33 #include <math.h>
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <stdio.h>
37 // needed to retrieve the timestamp in milliseconds and Sleep
38 #include <Windows.h>
39 
40 #include "COMPort.h"
41 #include "Protocol.h"
42 #include "EndpointRadarBaseBoard.h"
43 #include "EndpointRadarD2GL.h"
44 
45 
46 /*
47 ==============================================================================
48  2. LOCAL TYPES
49 ==============================================================================
50 */
51 
52 
53 /*
54 ==============================================================================
55  3. DATA
56 ==============================================================================
57 */
58 
59 static int32_t protocol_handle = -1;
60 static uint8_t endpoint_mcu_base = 0;
61 static uint8_t endpoint_d2gl = 0;
62 
63 volatile boolean completed = false;
64 uint32_t max_count = 20;
65 /*
66 ==============================================================================
67  4. LOCAL FUNCTION PROTOTYPES
68 ==============================================================================
69 */
70 
78 static int32_t connect_to_sensor(void);
79 
87 static int32_t query_communications_endpoints(void);
88 
96 static int32_t configure_sensor(void);
97 
105 static void on_error(int32_t err_code);
106 
107 
108 /*
109 ==============================================================================
110  5. LOCAL FUNCTIONS
111 ==============================================================================
112 */
113 
114 static int32_t connect_to_sensor(void)
115 {
116  char com_port_list[512];
117  char* current_port;
118 
119  /* retrieve a list of all available com ports */
120  com_port_list[0] = 0;
121  com_get_port_list(com_port_list, sizeof(com_port_list));
122 
123  /* iterate over the port list */
124  current_port = com_port_list;
125  while (current_port[0])
126  {
127  int32_t protocol_handle;
128 
129  /*
130  * find end of current port name in port list
131  * (port name is delimited by other ';' or '\0'
132  */
133  char* next_port = current_port;
134  while (next_port[0])
135  {
136  if (next_port[0] == ';')
137  {
138  /* replace ';' by '\0' to indicate end of current port name */
139  *next_port = 0;
140 
141  /* after a ';' another port name follows */
142  ++next_port;
143  break;
144  }
145  ++next_port;
146  }
147 
148  /* try to connect to current COM port */
149  printf("Trying to open COM port: %s ... ", current_port);
150  protocol_handle = protocol_connect(current_port);
151 
152  if (protocol_handle >= 0)
153  {
154  printf("OK.\n");
155  return protocol_handle;
156  }
157  else
158  {
159  printf("Failed.\n");
160  }
161 
162  /* prepare for next iteration */
163  current_port = next_port;
164  }
165 
166  return -1;
167 }
168 
169 static int32_t query_communications_endpoints(void)
170 {
171  int32_t num_endpoints;
172  uint8_t i;
173 
174  /* check number of endpoints */
175  num_endpoints = protocol_get_num_endpoints(protocol_handle);
176  if (num_endpoints < 0)
177  {
178  printf("Error: Could not find any endpoint.\n");
179  return -1;
180  }
181 
182  printf("Number of detected endpoints: %d\n", num_endpoints);
183  /* search for endpoint radar base */
184  printf("Searching for endpoint \"Radar Base\" ... ");
185  for (i = 1; i <= num_endpoints; ++i)
186  {
187  if (ep_radar_base_board_is_compatible_endpoint(protocol_handle, i) == 0)
188  {
189  endpoint_mcu_base = i;
190  break;
191  }
192  }
193  printf("%s\n", (endpoint_mcu_base != 0) ? "OK." : "Failed!");
194 
195  /* search for endpoint radar base */
196  printf("Searching for endpoint \"%s\" ... ", "D2GL-SC-FMCW");
197  for (i = 1; i <= num_endpoints; ++i)
198  {
199  if (ep_radar_d2gl_scfmcw_is_compatible_endpoint(protocol_handle, i) == 0)
200  {
201  endpoint_d2gl = i;
202  break;
203  }
204  }
205  printf("%s\n", (endpoint_d2gl != 0) ? "OK." : "Failed!");
206 
207 
208  if (endpoint_mcu_base == 0 || endpoint_d2gl == 0)
209  {
210  printf("Error: Not all required communication endpoints found for this demo\n");
211  return -1;
212  }
213  else
214  {
215  return 1;
216  }
217 }
218 
219 static int32_t configure_sensor(void)
220 {
221  int32_t return_code = 0;
222 
223  return return_code;
224 }
225 
226 static void on_error(int32_t err_code)
227 {
228  printf("Error Code 0x%06x: %s\n", err_code,
229  protocol_get_status_code_description(protocol_handle,
230  err_code));
231 
232  /* Close the connection */
233  /* ----------------------------- */
234  printf("Connection is closed now.\n ");
235  if (protocol_handle >= 0)
236  {
237  protocol_disconnect(protocol_handle);
238  }
239 }
240 
242 {
243  if( p_title)
244  printf("%s\n", p_title);
245 
246  printf("\t:max_distance : %.8f m\n", pData->max_distance_m);
247  printf("\t:min_distance : %.8f m\n", pData->min_distance_m);
248  printf("\t:frame_time : %.2f msec\n", pData->frame_time_sec*1e3);
249  printf("\t:number_of_samples : %u\n", pData->number_of_samples_nu);
250  printf("\t:hold_threshold : %u\n", pData->hold_threshold);
251  printf("\t:activation_threshold : %u\n", pData->activation_threshold);
252  printf("\t:number_of_chirps_per_frame : %u\n", pData->number_of_chirps_per_frame);
253  printf("\t:continuous_mode : %s\n", (pData->continuous_mode_bool ? "true" : "false"));
254  printf("\t:baseband_gain_stage : %s\n", (pData->baseband_gain_stage_bool ? "true" : "false"));
255  printf("\t:pulse_repetition_rate : %.2f msec\n", pData->pulse_repetition_rate_sec*1e3);
256  printf("\t:activate cfar : %s\n", (pData->activate_cfar == true) ? "true" : "false");
257 
258  return pData;
259 }
260 
261 void mcubase_consumption_cnf_callback(consumption_cnf_ctx_t *p_context, int32_t protocol_handle,
262  uint8_t endpoint, consumption_cnf_t *p_consumption)
263 {
264  printf("mcubase_consumption_cnf_callback called\n");
265  printf("\telements: %d\n", p_consumption->elements);
266  for (size_t i = 0; i < p_consumption->elements; i++)
267  {
268  consumption_t *pData = (p_consumption->p_consumption + i);
269  printf("\t\t%d: ", pData->index);
270  printf("%f %s\n", pData->value, pData->p_unit);
271  }
272  fflush(stdout);
273 }
274 
275 void mcubase_consumption_def_cnf_callback(consumption_def_cnf_ctx_t *p_context, int32_t protocol_handle,
276  uint8_t endpoint, consumption_def_host_t *p_consumption)
277 {
278  printf("mcubase_consumption_def_cnf_callback called\n");
279  printf("\telements: %d\n", p_consumption->consumption_label_elements);
280  for (size_t i = 0; i < p_consumption->consumption_label_elements; i++)
281  {
282  printf("\t\t%s\n", &p_consumption->pp_consumption_labels[i][0]);
283  }
284  fflush(stdout);
285 }
286 
287 void mcubase_para_store_callback(para_store_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, para_store_cnf_t *p_data)
288 {
289  printf("mcubase_para_store_callback called\n");
290  printf("\tno data is available!\n");
291 
292  fflush(stdout);
293 }
294 
295 void mcubase_para_factory_reset_callback(para_factory_reset_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, para_factory_reset_t *p_data)
296 {
297  printf("mcubase_para_factory_reset_callback called\n");
298  printf("\tno data is available!\n");
299  fflush(stdout);
300 }
301 
302 void mcubase_board_info_callback(board_info_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, board_info_cnf_t *p_data)
303 {
304  printf("mcubase_board_info_callback called\n");
305  printf("\tmajor version: %d\n", p_data->major_version);
306  printf("\tminor version: %d\n", p_data->minor_version);
307  printf("\trf shield type id: %s\n", p_data->rf_shield_type_id);
308  printf("\tdescription: %s\n", p_data->description);
309  fflush(stdout);
310 }
311 
312 
313 
314 
315 void fmcw_para_value_callback(void *p_context, int32_t protocol_handle,
316  uint8_t endpoint, fmcw_para_values_t *ps_para_values)
317 {
318  fmcw_para_values_t *pData = ps_para_values;
319 
320  log_fmcw_para_value(pData, "fmcw_para_value_callback:");
321 
322  fflush(stdout);
323 }
324 
325 
326 
327 
328 static void fmcw_para_value_def_callback(fmcw_para_values_def_cnf_ctx_t *p_context, int32_t protocol_handle,
329  uint8_t endpoint, fmcw_para_value_def_host_t *ps_para_values)
330 {
331 
332  fmcw_para_value_def_host_t *pData = ps_para_values;
333 
334  printf("fmcw_para_value_def_callback:\n");
335 
336  printf("\t:max_distance lower_boundary : %.2f m\n", pData->max_distance_m_lower_boundary);
337  printf("\t:max_distance upper_boundary : %.2f m\n", pData->max_distance_m_upper_boundary);
338  printf("\t:max_distance step_size : %.3f m\n", pData->max_distance_m_step_size);
339 
340  printf("\t:min_distance lower_boundary : %.1f m\n", pData->min_distance_m_lower_boundary);
341  printf("\t:min_distance upper_boundary : %.1f m\n", pData->min_distance_m_upper_boundary);
342  printf("\t:min_distance step_size : %.3f m\n", pData->min_distance_m_step_size);
343 
344  printf("\t:frame time lower boundary : %f msec\n", pData->frame_time_sec_lower_boundary*1e3);
345  printf("\t:frame time upper boundary : %f msec\n", pData->frame_time_sec_upper_boundary*1e3);
346  printf("\t:frame_time step_size : %.0f usec\n", pData->frame_time_sec_step_size*1e6);
347 
348  printf("\t:frame rate upper boundary : %f Hz\n", 1.0/pData->frame_time_sec_lower_boundary);
349  printf("\t:frame rate lower boundary : %f Hz\n", 1.0/pData->frame_time_sec_upper_boundary);
350 
351  printf("\t:size_elems: %d \n", pData->size_elems);
352  for (int i = 0; i < pData->size_elems; i++)
353  {
354  printf("\t\t%d", pData->p_sample_list[i]);
355  }
356  printf("\n");
357 
358  printf("\t:hold_threshold_lower_boundary : %u\n", pData->hold_threshold_lower_boundary);
359  printf("\t:hold_threshold_upper_boundary : %u\n", pData->hold_threshold_upper_boundary);
360  printf("\t:hold_threshold_step_size : %u\n", pData->hold_threshold_step_size);
361  printf("\t:activation_threshold_lower_boundary : %u\n", pData->activation_threshold_lower_boundary);
362  printf("\t:activation_threshold_upper_boundary : %u\n", pData->activation_threshold_upper_boundary);
363  printf("\t:activation_threshold_step_size : %u\n", pData->activation_threshold_step_size);
364 
365  printf("\t:number_of_chirps_per_frame_lower_boundary : %u\n", pData->number_of_chirps_per_frame_lower_boundary);
366  printf("\t:number_of_chirps_per_frame_upper_boundary : %u\n", pData->number_of_chirps_per_frame_upper_boundary);
367  printf("\t:number_of_chirps_per_frame_step_size : %u\n", pData->number_of_chirps_per_frame_step_size);
368 
369 
370  printf("\t:pulse_repetition_rate lower_boundary : %.2f msec\n", pData->pulse_repetition_time_sec_lower_boundary*1e3);
371  printf("\t:pulse_repetition_rate upper_boundary : %.2f msec\n", pData->pulse_repetition_time_sec_upper_boundary*1e3);
372  printf("\t:pulse_repetition_rate step_size : %.0f usec\n", pData->pulse_repetition_time_sec_step_size*1e6);
373 
374  fflush(stdout);
375 
376 }
377 
378 
379 
380 void fmcw_result_cnf_callback(void *p_context, int32_t protocol_handle,
381  uint8_t endpoint, fmcw_result_cnf_t *p_result)
382 {
383  static uint32_t result_count = 0;
384  if (result_count > max_count)
385  completed = true;
386  result_count++;
387 
388  char statusArray[][20] = { "NOT_DETECTED", "STATIC_TARGET", "UNSURE_TARGET", "MOVING_TARGET" };
389  char dirArray[][20] = { "NOT_DETECTED", "STATIC", "APPROACHING", "DEPARTING" };
390  printf("fmcw_result_cnf_callback called\n");
391 
392  printf("\tresult cnt: %d\n", p_result->result_count);
393  printf("\tframe number: %d\n", p_result->frame_number);
394 
395  printf("\trange: %f m\n", p_result->range_m);
396  printf("\tstrength: %f\n", p_result->strength);
397  printf("\tvelocity: %f m/s\n", p_result->velocity_mps);
398 
399  printf("\ttarget_status: %s\n", statusArray[p_result->target_status]);
400  printf("\tdirection_of_movement: %s\n", dirArray[p_result->direction_of_movement]);
401 
402 }
403 
404 
405 
406 typedef struct {
412 
413 typedef struct {
417 
418 
419 
420 void fmcw_adv_result_cnf_callback(void *p_context, int32_t protocol_handle,
421  uint8_t endpoint, fmcw_adv_result_cnf_t *p_result)
422 {
423 
424  char statusArray[][20] = { "NOT_DETECTED", "STATIC_TARGET", "UNSURE_TARGET", "MOVING_TARGET" };
425  char dirArray[][20] = { "NOT_DETECTED", "STATIC", "APPROACHING", "DEPARTING" };
426 
427  show_result_options_t *p_options = (show_result_options_t *) p_context;
428  if (p_options->show_output)
429  {
430 
431  printf("fmcw_adv_result_cnf_callback called\n");
432 
433  if (p_options->show_output)
434  {
435 
436  bool show_details = true;
437  if (p_options->show_output_on_target && p_result->target_status == 0)
438  {
439  show_details = false;
440  }
441 
442  if (show_details)
443  {
444  printf("\tresult cnt: %d\n", p_result->result_count);
445  printf("\tframe number: %d\n", p_result->frame_number);
446 
447  printf("\trange [m]: %f\n", p_result->range_m);
448  printf("\tstrength: %f\n", p_result->strength);
449  printf("\tvelocity_mps: %f\n", p_result->velocity_mps);
450 
451  printf("\ttarget_status: %s\n", statusArray[p_result->target_status]);
452  printf("\tdirection_of_movement: %s\n", dirArray[p_result->direction_of_movement]);
453  printf("\tfft size: 256\n"); // Hard coded in device!
454  }
455 
456  if (p_options->show_activation_data)
457  {
458  printf("\tnum_activation_data : %u\n", p_result->num_activation_data);
459  for (uint32_t i = 0; i < p_result->num_activation_data; i++)
460  {
461  printf("activation threshhold data[%d]: %f\n", i, p_result->p_activation_data[i]);
462  }
463  }
464 
465  if (p_options->show_activation_data)
466  {
467  printf("\tnum_hold_data : %u\n", p_result->num_hold_data);
468  for (uint32_t i = 0; i < p_result->num_hold_data; i++)
469  {
470  printf("hold treshhold data[%d]: %f\n", i, p_result->p_hold_data[i]);
471  }
472  }
473  }
474  fflush(stdout);
475  }
476 }
477 
479  uint8_t endpoint, fmcw_get_shield_info_cnf_t *p_result)
480 {
481  printf("\trf_frequency: %d kHz\n", p_result->rf_frequency_khz);
482  printf("\tbandwidth: %d MHz\n", p_result->bandwidth_mhz);
483  printf("\tmajor version: %d\n", p_result->major_version);
484  printf("\tminor version: %d\n", p_result->minor_version);
485  printf("\tnum_tx_antenna: %d\n", p_result->num_tx_antenna);
486  printf("\tnum_rx_antenna: %d\n", p_result->num_rx_antenna);
487  printf("\trf shield type id: %s\n", p_result->rf_shield_type_id);
488  printf("\tdescription: %s\n", p_result->description);
489  printf("\tmodulation: %s\n", p_result->modulation);
490  printf("\tup_chirp_time: %.0f usec\n", p_result->up_chirp_time_s*1e6);
491 
492  fflush(stdout);
493 
494 }
495 
496 typedef struct
497 {
498  uint8_t used_rx[8];
499  uint8_t used_rx_count;
500 
501 }RX_Info_t;
502 
503 static void proces_rx_info(uint8_t rx_mask, RX_Info_t *rx_info)
504 {
505 
506  int i = 0;
507  while (i < 8)
508  {
509  if (((rx_mask >> i) & 0x01) == 1)
510  {
511  rx_info->used_rx[rx_info->used_rx_count] = i + 1;
512  rx_info->used_rx_count++;
513  }
514  i++;
515  }
516 }
517 
518 // called every time ep_radar_base_get_frame_data method is called to return measured time domain signals
519 static void process_received_data(const get_raw_data_cnf_t* frame_info)
520 {
521  // Print the sampled data which can be found in frame_info->sample_data
522 
534  RX_Info_t rx_info = { { 0 }, 0 };
535 
536  proces_rx_info(frame_info->rx_mask, &rx_info);
537 
538  uint32_t num_chan_per_ant = (frame_info->data_format == EP_RADAR_BASE_RX_DATA_REAL ? 1 : 2);
539  /* TODO:
540  I think in the the follwoing two line it should be rx_info.used_rx_count instead of the frame_info->num_rx_antennas.
541  In the EndPointRadarBase.c of FW it should actually also be rx_info.used_rx_count. Need Discussion.
542  */
543  uint32_t chrip_inc = frame_info->num_samples_per_chirp * num_chan_per_ant * frame_info->num_rx_antennas;
544  uint32_t total_samle_count = frame_info->num_chirps *
545  frame_info->num_samples_per_chirp *
546  frame_info->num_rx_antennas *
547  num_chan_per_ant;
548  uint8_t chrip_nr = 0;
549  uint8_t rx_nr = 0;
550  uint8_t adc_nr = 0;
551  uint8_t sample_nr = 0;
552 
553  for (uint32_t i = 0; i < total_samle_count; i++)
554  {
555  chrip_nr = (i / chrip_inc);
556  rx_nr = ((i % chrip_inc) / (num_chan_per_ant * frame_info->num_samples_per_chirp));
557  adc_nr = ((i % (chrip_inc / rx_info.used_rx_count)) / (frame_info->num_samples_per_chirp));
558  sample_nr = (i % frame_info->num_samples_per_chirp);
559  printf("\t\t");
560  printf("%d, ", frame_info->frame_number);
561  printf("%d, ", chrip_nr);
562  printf("%d, ", rx_info.used_rx[rx_nr]);
563  printf("%d, ", adc_nr);
564  printf("%d, ", sample_nr);
565  printf("%f\n", frame_info->sample_data[i]);
566 
567  }
568  return;
569 }
570 
571 
572 void fmcw_get_raw_data_cnf_callback(get_raw_data_cnf_ctx_t *p_context, int32_t protocol_handle,
573  uint8_t endpoint, get_raw_data_cnf_t *p_raw_data)
574 {
575 
576  show_raw_data_options_t *p_show_raw_data_options = (show_raw_data_options_t*)p_context;
577  static int count = 0;
578  printf("fmcw_get_raw_data_cnf_callback called: %d, %d\r\n", count, p_raw_data->frame_number);
579 
580  if (p_show_raw_data_options && p_show_raw_data_options->show_raw_data_header)
581  {
582  printf("\tframe number: %d\n", p_raw_data->frame_number);
583  printf("\tnum_chirps: %d\n", p_raw_data->num_chirps);
584  printf("\tnum_samples_per_chirp: %d\n", p_raw_data->num_samples_per_chirp);
585  printf("\trx_mask: %d\n", p_raw_data->rx_mask);
586  }
587 
588  if(p_show_raw_data_options && p_show_raw_data_options->show_raw_data)
589  {
590  printf(" ----------------- raw data -------------------------\n");
591  process_received_data(p_raw_data);
592  printf(" ----------------------------------------------------\n");
593  }
594  count++;
595 
596 }
597 
598 
599 int32_t fmcw_set_parameter_helper(uint32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *p_para, char *text)
600 {
601  int32_t status_code;
602 
603  log_fmcw_para_value(p_para, text);
604 
605  status_code = ep_radar_d2gl_scfmcw_para_set_value_req(protocol_handle, endpoint, p_para);
606 
607  printf("req_result: 0x%04x, %s\n", status_code & 0xFFFF,
608  protocol_get_status_code_description(protocol_handle, status_code));
609 
610  if ((status_code & 0xFFFF) == PROTOCOL_STATUS_OK)
611  {
612  Sleep(200);
613  protocol_poll_receive_once(protocol_handle);
614  fflush(stdout);
615  }
616  return status_code;
617 }
618 
619 static bool signal_parameter_receive = false;
620 
621 void fmcw_para_value_copy_callback(void *p_context, int32_t protocol_handle,
622  uint8_t endpoint, fmcw_para_values_t *ps_para_values)
623 {
624  fmcw_para_values_t *pData = ps_para_values;
625  if (p_context != NULL)
626  {
627  memcpy(p_context, ps_para_values, sizeof(fmcw_para_values_t));
628  }
629  signal_parameter_receive = true;
630 }
631 
632 
634 {
635  uint32_t timeoutCount = 20;
636  void *p_prev_context = NULL;
637 
638  signal_parameter_receive = false;
640  ep_radar_d2gl_scfmcw_para_value_req(protocol_handle, endpoint_d2gl);
641  while(!signal_parameter_receive && timeoutCount > 0)
642  {
643  Sleep(50);
644  timeoutCount--;
645  }
646  /* register the old callback again! */
647  ep_radar_d2gl_scfmcw_set_para_value_cb(prev_cb, p_prev_context, NULL);
648 
649  if (timeoutCount == 0)
650  {
651  printf("***** ERROR: No response!!\n");
652  fflush(stdout);
653  return false;
654  }
655  return true;
656 }
657 
658 /*
659 ==============================================================================
660 4. EXPORTED FUNCTIONS
661 ==============================================================================
662 */
663 
664 
665 int main()
666 {
667  int32_t return_code = 0;
668 
669 
670  /* connect to a sensor board */
671  /* ------------------------- */
672  protocol_handle = connect_to_sensor();
673  if (protocol_handle < 0)
674  {
675  printf("Error: Could not find a sensor board.\n");
676  return protocol_handle;
677  }
678 
679  /* search for relevant endpoints */
680  /* ----------------------------- */
681  if (query_communications_endpoints() == 1)
682  {
683  /* configure chip to power on reset parameters */
684  return_code = configure_sensor();
685  if (return_code & 0xFFFF)
686  {
687  on_error(return_code);
688  return (return_code & 0xFFFF);
689  }
690 
691  /* callback settings: */
692 
693  show_result_options_t show_result_options = {
694  .show_output = false,
695  .show_output_on_target = false,
696  .show_activation_data = false,
697  .show_hold_data = false,
698  };
699 
700 
701  printf("---- register callbacks ----\n");
702 
706  ep_radar_d2gl_scfmcw_set_para_def_cb(fmcw_para_value_def_callback, NULL);
709  &(show_result_options_t) { .show_output = false, .show_output_on_target = false, .show_activation_data = false, .show_hold_data = false } );
710 
716 
717  {
718  printf("Trying to get a device info ...");
719 
720  Firmware_Information_t fw_info;
721  return_code = protocol_get_firmware_information(protocol_handle, &fw_info);
722 
723  printf("%s\n", ((return_code & 0xFFFF) == 0) ? "OK." : "Failed!");
724  if ((return_code & 0xFFFF))
725  {
726  goto ON_ERROR;
727  }
728 
729  printf("FW info: \"%s\": %d.%d.%d\n", fw_info.description, fw_info.version_major, fw_info.version_minor, fw_info.version_build);
730  fflush(stdout);
731  }
732 
733 
734  printf("---- fmcw: get shield info ----\n");
735  ep_radar_d2gl_scfmcw_get_shield_info_req(protocol_handle, endpoint_d2gl);
736  protocol_poll_receive_once(protocol_handle);
737  fflush(stdout);
738 
739 
740 
741 
742 
743  {
744  printf("---- mcu base: factory reset ----\n");
745  ep_radar_base_board_para_factory_reset_req(protocol_handle, endpoint_mcu_base);
746  protocol_poll_receive_once(protocol_handle);
747  fflush(stdout);
748  }
749 
750  {
751  printf("---- fmcw: get parameter definition ----\n");
752  ep_radar_d2gl_scfmcw_para_value_def_req(protocol_handle, endpoint_d2gl);
753  fflush(stdout);
754  Sleep(500);
755  protocol_poll_receive_once(protocol_handle);
756  fflush(stdout);
757  }
758 
759  fmcw_para_values_t settings;
760  if (read_parameter_helper(&settings))
761  {
762  log_fmcw_para_value(&settings, "read parameter: ");
763  }
764  else
765  {
766  printf("**** can't read parameter! \n");
767 
768  }
769  fflush(stdout);
770 
771  settings.number_of_chirps_per_frame = 5;
772  settings.frame_time_sec = 100 * 1e-3F;
773 
774  printf("**** apply new settings now: ... \n");
775  fflush(stdout);
776 
777  return_code = fmcw_set_parameter_helper(protocol_handle, endpoint_d2gl, &settings, "settings for the test");
778  if ((return_code & 0xFFFF) > 0)
779  goto ON_ERROR;
780 
782  &(show_result_options_t) { .show_output = true, .show_output_on_target = true, .show_activation_data = true, .show_hold_data = true } );
783 
784  return_code = ep_radar_d2gl_scfmcw_adv_result_req(protocol_handle, endpoint_d2gl, 50);
785  if ((return_code & 0xFFFF) > 0)
786  goto ON_ERROR;
787 
789  &(show_raw_data_options_t) { .show_raw_data_header = true, .show_raw_data = true } );
790 
791  return_code = ep_radar_d2gl_scfmcw_get_raw_data_req(protocol_handle, endpoint_d2gl, 50);
792  if ((return_code & 0xFFFF) > 0)
793  goto ON_ERROR;
794 
795  printf("start getting data....");
796  fflush(stdout);
797  uint32_t count = 20;
798  while (count)
799  {
800  printf("count: %d\n", count);
801  Sleep(50);
802  protocol_poll_receive_once(protocol_handle);
803  count--;
804  }
805 
806  printf("stop getting data....\n");
807  fflush(stdout);
808  return_code = ep_radar_d2gl_scfmcw_adv_result_req(protocol_handle, endpoint_d2gl, 0);
809  if ((return_code & 0xFFFF) > 0)
810  goto ON_ERROR;
811 
812  return_code = ep_radar_d2gl_scfmcw_get_raw_data_req(protocol_handle, endpoint_d2gl, 0);
813  if ((return_code & 0xFFFF) > 0)
814  goto ON_ERROR;
815  } // if (query_communications_endpoints() == 1)
816  printf("Wait for termination!\n");
817  fflush(stdout);
818  Sleep(5000);
819 
820 ON_ERROR:
821  if ((return_code & 0xFFFF))
822  {
823  printf("Error Code 0x%06x: %d, %s\n", return_code, return_code,
824  protocol_get_status_code_description(protocol_handle, return_code));
825  }
826 
827  /* finally, close the connection */
828  /* ----------------------------- */
829  printf("Connection is closed now.\n ");
830  protocol_disconnect(protocol_handle);
831  fflush(stdout);
832 
833  return (return_code & 0xFFFF);
834 }
void ep_radar_base_board_consumption_def_cb(consumption_def_cnf_callback_t callback, consumption_def_cnf_ctx_t *p_context)
uint32_t num_samples_per_chirp
Definition: radar_common.h:178
void ep_radar_d2gl_scfmcw_set_adv_result_cb(fmcw_adv_result_cnf_callback_t callback, void *p_context)
uint32_t max_count
uint8_t baseband_gain_stage_bool
This file contains the API methods applicable generically to Industrial radar Baseboard based Demos.
uint8_t used_rx[8]
void ep_radar_base_board_para_store_cb(para_store_cnf_callback_t callback, para_store_cnf_ctx_t *p_context)
void ep_radar_d2gl_scfmcw_set_result_cb(fmcw_result_cnf_callback_t callback, void *p_context)
fmcw_para_values_t * log_fmcw_para_value(fmcw_para_values_t *pData, char *p_title)
void mcubase_para_factory_reset_callback(para_factory_reset_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, para_factory_reset_t *p_data)
void ep_radar_d2gl_scfmcw_set_shield_info_cb(fmcw_get_shield_info_cnf_callback_t callback, fmcw_get_shield_info_cnf_ctx_t *p_context)
const float * sample_data
Definition: radar_common.h:162
int32_t ep_radar_d2gl_scfmcw_para_value_def_req(int32_t protocol_handle, uint8_t endpoint)
void ep_radar_base_board_board_info_cb(board_info_cnf_callback_t callback, board_info_cnf_ctx_t *p_context)
This structure contains information about the firmware.
Definition: Protocol.h:273
int32_t ep_radar_d2gl_scfmcw_is_compatible_endpoint(int32_t protocol_handle, uint8_t endpoint)
This function checks if an endpoint in a device is a Radar D2GL endpoint.
void fmcw_adv_result_cnf_callback(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_adv_result_cnf_t *p_result)
This struct holds all information about a single frame of radar data.
Definition: radar_common.h:160
void ep_radar_base_board_para_factory_reset_cb(para_factory_reset_cnf_callback_t callback, para_factory_reset_cnf_ctx_t *p_context)
This file defines the API to access a serial communication port.
void ep_radar_d2gl_scfmcw_set_para_def_cb(fmcw_para_values_def_cnf_callback_t callback, fmcw_para_values_def_cnf_ctx_t *p_context)
uint16_t version_build
Definition: Protocol.h:279
int32_t protocol_poll_receive_once(int32_t protocol_handle)
Definition: Protocol.c:1151
int main()
This file defines the basic API to access Infineon sensor devices.
#define PROTOCOL_STATUS_OK
Definition: Protocol.h:91
Rx_Data_Format_t data_format
Definition: radar_common.h:203
uint16_t version_major
Definition: Protocol.h:277
int32_t protocol_get_num_endpoints(int32_t protocol_handle)
This function returns the number of endpoints in the connected device.
Definition: Protocol.c:755
uint16_t version_minor
Definition: Protocol.h:278
int32_t protocol_connect(const char *port_name)
This function establishes a connection to a device through a COM port.
Definition: Protocol.c:573
void fmcw_get_raw_data_cnf_callback(get_raw_data_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, get_raw_data_cnf_t *p_raw_data)
int32_t ep_radar_d2gl_scfmcw_get_shield_info_req(int32_t protocol_handle, uint8_t endpoint)
int32_t ep_radar_base_board_is_compatible_endpoint(int32_t protocol_handle, uint8_t endpoint)
This function checks if an endpoint in a device is a Radar Baseboard endpoint.
void mcubase_consumption_cnf_callback(consumption_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, consumption_cnf_t *p_consumption)
int32_t ep_radar_d2gl_scfmcw_para_set_value_req(int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *p_data)
void mcubase_consumption_def_cnf_callback(consumption_def_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, consumption_def_host_t *p_consumption)
void protocol_disconnect(int32_t protocol_handle)
This function closes an open connection.
Definition: Protocol.c:723
int32_t fmcw_set_parameter_helper(uint32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *p_para, char *text)
void ep_radar_d2gl_scfmcw_set_raw_data_cb(get_raw_data_cnf_callback_t callback, void *p_context)
int32_t ep_radar_d2gl_scfmcw_adv_result_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
volatile boolean completed
consumption_t * p_consumption
int32_t protocol_get_firmware_information(int32_t protocol_handle, Firmware_Information_t *information)
This function returns the information about the firmware of the connected device.
Definition: Protocol.c:768
void fmcw_get_shield_info_cnf_callback(fmcw_get_shield_info_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_get_shield_info_cnf_t *p_result)
void(* fmcw_para_values_cnf_callback_t)(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *ps_para_values)
This is the callback type executed on a parameter value confirmation event, triggered,...
int32_t ep_radar_d2gl_scfmcw_para_value_req(int32_t protocol_handle, uint8_t endpoint)
This function is used to request the parameter values,.
void fmcw_para_value_callback(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *ps_para_values)
fmcw_para_values_cnf_callback_t ep_radar_d2gl_scfmcw_set_para_value_cb(fmcw_para_values_cnf_callback_t callback, void *p_context, void **prev_context)
void fmcw_result_cnf_callback(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_result_cnf_t *p_result)
void fmcw_para_value_copy_callback(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *ps_para_values)
void ep_radar_base_board_consumption_cb(consumption_cnf_callback_t callback, consumption_cnf_ctx_t *p_context)
uint8_t number_of_chirps_per_frame
const char * protocol_get_status_code_description(int32_t protocol_handle, int32_t status_code)
This function returns a human readable description of a status or error code.
Definition: Protocol.c:1023
bool read_parameter_helper(fmcw_para_values_t *p_para)
uint32_t com_get_port_list(char *port_list, size_t buffer_size)
This function returns a list of available COM ports.
void mcubase_board_info_callback(board_info_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, board_info_cnf_t *p_data)
int32_t ep_radar_d2gl_scfmcw_get_raw_data_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
void mcubase_para_store_callback(para_store_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, para_store_cnf_t *p_data)
int32_t ep_radar_base_board_para_factory_reset_req(int32_t protocol_handle, uint8_t endpoint)
This file contains the API methods applicable generically to Industrial radar demo Distance2GoL.